class Data{
  static AddZero(num){
    if(num<10){
      num = "0"+num;
    }
    return num;
  }
  static HandlePlayCount(playCount){
    playCount = Math.ceil(playCount/10000);
    return playCount
  }
  static HandleDuration(duration){
    var second = duration/1000;
    var minute = parseInt(second/60);
    second = parseInt(second%60);
    minute = this.AddZero(minute);
    second = this.AddZero(second);
    return minute + ":" + second
  }
  static handleStar(num){
    var res = [];
    for(var i = 0 ; i < 5 ; i++){
      if(num>=2){
          res.push(2);
      }else if(num>0){
          res.push(parseFloat(num.toFixed(1)));
      }else{
          res.push(0);
      }
      num -= 2;
    }
    return res;
  }
  static handleinTheaterData(res){
    var arr = [];
    res.forEach(item=>{
      var {_id,pic,title,raiting} = item;
      var star = this.handleStar(raiting);
      arr.push({_id,pic,title,rating:parseFloat(raiting),star});
    });
    return arr;
  }
  static handleHttpData(res){
    var arr = [];
    res.forEach(item=>{
      var {_id,pic,title,rating} = item;
      var star = Data.handleStar(rating);
      arr.push({_id,pic,title,rating:parseFloat(rating),star});
    });
    return arr;
  }
  static handleStr(str){
    str = str + "";
    if(str.length>6){
      str = str.slice(0,6) + "...";
    }
    return str;
  }
}
module.exports = {
  Data
}